package com.resou.reader.dialog.limitedrecharge;

import com.resou.reader.api.ApiImp;
import com.resou.reader.api.entry.ActivityRechargePrice;
import com.resou.reader.api.service.ActivityService;
import com.resou.reader.base.ResouBasePresenter;
import com.resou.reader.mine.IView.UserInstance;

import java.util.List;

public class LimitedRechargePresenter extends ResouBasePresenter<LimitedRechargeContract.View> implements LimitedRechargeContract.Presenter {
    private static final String TAG = "LimitedPresente-App";
    private final ActivityService mService;

    public LimitedRechargePresenter(LimitedRechargeContract.View view) {
        super(view);
        mService = ApiImp.getInstance().getService(ActivityService.class);
    }

    @Override
    public void activateRechargeActivity() {
        addCompositeDisposable(
                mService.startRechargeActivity(UserInstance.getToken(), 12)
                        .subscribeOn(getIOSchedulers())
                        .observeOn(getIOSchedulers())
                        .subscribe(result -> {
//                            int code = result.getCode();
//                            if (code == 0) {
//                                ToastUtil.makeShortToast("激活三天限时充值活动成功");
//                            }
                        }, throwable -> {
//                            Log.d(TAG, "激活三天限时充值活动错误:错误信息：" + throwable.getMessage());
                        })
        );
    }

    public void loadRechargePrice(int activityId) {
        addCompositeDisposable(
                mService.getRechargePrice(activityId)
                        .subscribeOn(getIOSchedulers())
                        .observeOn(getMainSchedulers())
                        .subscribe(result -> {
                            List<ActivityRechargePrice> data = result.getData();
                            if (data != null && data.size() > 0) {
                                mView.showPrice(data);
                            }
                        }, throwable -> {

                        })
        );
    }
}
